﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace TuiXin
{
    public class INIFile
    {

        private string path;//INI文件名
        public string FilePath
        {
            get
            {
                return (this.path);
            }
            set
            {
                this.path = value;
            }
        }

        #region Define


        //声明读写INI文件的API函数
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        #endregion

        public INIFile(string INIPath)
        {

            this.path = INIPath;


        }
        public INIFile()
        {
            this.path = Environment.CurrentDirectory + @"\Config.ini";
            if (!File.Exists(this.path))
            {
                this.path = @"L:\Red\Config.ini";
            }
        }

        public void SetValue(string Section, string Key, string Value)
        {

            WritePrivateProfileString(Section, Key, Value, this.path);

        }

        public string GetValue(string Section, string Key)
        {

            StringBuilder temp = new StringBuilder(255);

            int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);

            return temp.ToString();

        }

    }
}
